# Comment/uncomment the following line to disable/enable debugging
#DEBUG = y

#KERNELDIR ?= /lib/modules/$(shell uname -r)/build

CC=/opt/uClinux/bfin-uclinux/bin/bfin-uclinux-gcc
KERNELDIR = /opt/uClinux-dist/linux-2.6.x

all: modules testespi

# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DDEBUG # "-O" is needed to expand inlines
else
# there is some kind of bug related to optimization -O2 and the blackfin:
# http://blackfin.uclinux.org/tracker/?func=detail&atid=141&aid=1067&group_id=17
#  DEBFLAGS = -O2
  DEBFLAGS = -O0
endif

CFLAGS_MOD += $(DEBFLAGS) -Wall
CFLAGS_MOD += $(LDDINC)
CFLAGS += $(DEBFLAGS) -Wall -Wl,-elf2flt

ifneq ($(KERNELRELEASE),)
# call from kernel build system

cbfxs-objs := main.o

obj-m	:= cbfxs.o

else

PWD       := $(shell pwd)

modules:
	export PATH=/opt/uClinux/bfin-uclinux/bin:$$PATH;$(MAKE) -C $(KERNELDIR) M=$(PWD) CFLAGS="$(CFLAGS_MOD)" LDDINC=-I$(PWD)/../include modules

endif



clean:
	rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
	rm -rf testespi

depend .depend dep:
	$(CC) $(CFLAGS) -M *.c > .depend


ifeq (.depend,$(wildcard .depend))
include .depend
endif

install: all
	ncftpput -u root -p uClinux 10.100.4.50 /tmp cbfxs.tar
	ncftpput -u root -p uClinux 10.100.4.50 /tmp testespi
	ncftpput -u root -p uClinux 10.100.4.50 /tmp cbfxs.ko
	ncftpput -u root -p uClinux 10.100.4.50 /tmp configuraspi
	ncftpput -u root -p uClinux 10.100.4.50 /tmp tt

